import javafx.util.Pair;

import java.util.HashSet;

/**
* @description: 874. 模拟行走机器人
* @author hewei
* @date 2022/9/13 16:15
* @version 1.0
*/

public class RobotSim {

    public static void main(String[] args) {
        int[] nums = {4,-1,3};
        System.out.println(new RobotSim().robotSim(nums, new int[0][0]));
    }

    public int robotSim(int[] commands, int[][] obstacles) {
        int[][] temp = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
        HashSet<Pair<Integer, Integer>> set = new HashSet<>();
        for (int[] obstacle : obstacles) {
            set.add(new Pair<>(obstacle[0], obstacle[1]));
        }
        int ans = 0;
        int x = 0;
        int y = 0;
        int des = 0;
        for (int command : commands) {
            switch (command) {
                case -2:
                {
                    des -= 1;
                    if (des == -1) des = 3;
                    break;
                }
                case -1:
                {
                    des += 1;
                    if (des == 4) des = 0;
                    break;
                }
                default:
                {
                    while (command-- > 0) {
                        int xx = x + temp[des][0];
                        int yy = y + temp[des][1];
                        if (set.contains(new Pair<>(xx, yy))) break;
                        x = xx;
                        y = yy;
                        ans = Math.max(ans, x * x + y * y);
                    }
                }
            }
        }
        return ans;
    }
}
